package cn.com.visionsky.bocsz.bda.webservice.handler.cst_lbl_ast_query;

import cn.com.visionsky.bocsz.bda.webservice.handler.history_trans_query.HistoryTransQueryTest;
import cn.com.visionsky.bocsz.bda.webservice.ws.Application;
import cn.com.visionsky.bocsz.bda.webservice.ws.Reply;
import cn.com.visionsky.bocsz.bda.webservice.ws.client.Client;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;

public class CstLblAstQueryTest {
    private static final Logger logger = LoggerFactory.getLogger(CstLblAstQueryTest.class);

    private final static String UID = "10000000000000000000000000000001";
    private final static String SRL_NUM = "1";
    private final static String TXN_CODE = "1000000003";
    private final static String MSG_ID = "10003";
    private final static String SYS_ID = "00001";
    private final static String TXN_DATE = "20181226";
    private final static String INST_NO = "001";
    private final static String USR_ID = "0000000000000001";
    private final static String USR_BRNH = "0000000000000001";

    public static void main(String[] args) throws IOException, URISyntaxException {
        File contextDir = new File(HistoryTransQueryTest.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParentFile();
        logger.info("context dir: " + contextDir.getAbsolutePath());

        final Application application = new Application();
        application.setTxnCode(TXN_CODE);
        application.setSrlNum(SRL_NUM);
        application.setUid(UID);
        application.setMsgId(MSG_ID);
        application.setSysId(SYS_ID);
        application.setTxnDate(TXN_DATE);
        application.setInstNo(INST_NO);
        application.setUsrBrnh(USR_BRNH);
        application.setUsrId(USR_ID);

        logger.info("TXN_CODE: " + application.getTxnCode());
        logger.info("SRL_NUM: " + application.getSrlNum());
        logger.info("UID: " + application.getUid());
        logger.info("MSG_ID: " + application.getMsgId());
        logger.info("SYS_ID: " + application.getSysId());
        logger.info("TXN_DATE: " + application.getTxnDate());
        logger.info("INST_NO: " + application.getInstNo());
        logger.info("USR_BRNH: " + application.getUsrBrnh());
        logger.info("USR_ID: " + application.getUsrId());


        final File clientInputFile = new File(contextDir, "ClientInput.txt");
        if (!clientInputFile.exists()) logger.info("ClientInput.txt not exist!");

        String clientInputText = FileUtils.readFileToString(clientInputFile, "UTF-8");
        application.setFullTxt(clientInputText);
        logger.info("application FullTxt: " + application.getFullTxt());

        final Reply reply = Client.rout(application);
        logger.info("ResultCode: " + reply.getResultCode() + ", ResultMsg: " + reply.getResultMsg());
        logger.info("reply FullTxt: " + reply.getFullTxt());

        FileUtils.write(new File(contextDir, "ClientOutput.txt"), reply.getFullTxt(), "UTF-8");

    }
}
